package simpleMesh;

import hdgeom.primitives.AbstractFace;

import java.util.ArrayList;
import java.util.Collections;

import processing.core.PGraphics;
import processing.core.PVector;
import simpleGeom.MeshNode;

public class Face extends AbstractFace {
	public ArrayList<PVector> vertices = new ArrayList<PVector>();
	public int id;

	public Face() {
	}

	public Face(PVector v1, PVector v2, PVector v3) {
		vertices.add(v1);
		vertices.add(v2);
		vertices.add(v3);
	}

	public Face(PVector v1, PVector v2, PVector v3, PVector v4) {
		vertices.add(v1);
		vertices.add(v2);
		vertices.add(v3);
		vertices.add(v4);
	}

	public int size() {
		return vertices.size();
	}

	public PVector get(int i) {
		return vertices.get(i);
	}

	public PVector set(int i, PVector v) {
		return vertices.set(i, v);
	}

	public void turn() {
		Collections.reverse(vertices);
	}

	public PVector normal() {
		PVector v = PVector.sub(vertices.get(1), vertices.get(0));
		PVector u = PVector.sub(vertices.get(2), vertices.get(0));
		PVector normal = new PVector();
		PVector.cross(v, u, normal);
		normal.normalize();
		return normal;
	}

	public void addNode(PVector n) {
		vertices.add(n);
		// TODO Auto-generated method stub

	}

	public PVector getNode(int j) {
		// TODO Auto-generated method stub
		return vertices.get(j);
	}
	

	public int getNNodes() {
		// TODO Auto-generated method stub
		return vertices.size();
	}

	@Override
	public int getNumVertices() {
		// TODO Auto-generated method stub
		return vertices.size();
	}

	@Override
	public void getPosition(int i, float[] coords) {
		// TODO Auto-generated method stub
		PVector v = vertices.get(i);
		coords[0] = v.x;
		coords[1] = v.y;
		coords[2] = v.z;
	}

	@Override
	public void setPosition(int i, float x, float y, float z) {
		// TODO Auto-generated method stub
		PVector v = vertices.get(i);
		v.set(x, y, z);

	}

}
